<?php
/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
class User extends AppModel{
    var $name = 'User';
    var $validate = array(
        'first_name'=> array(
            'rule' => 'notEmpty',
            'message' => 'This field cannot be left blank'
        ),
        
        'last_name' => array(
            'rule' => 'notEmpty',
            'message' => 'This field cannot be left blank'
        ),

        'passwd' => array(
            'rule' => 'notEmpty',
            'message' => 'This field cannot be left blank'
        ),
        
        'email_addr' => array(
            'rule' => 'email',
            'message' => 'Please supply a valid email address.'
        )

        
        );
        
    function  beforeValidate($options = array()) {
        if(!$this->id){
            $result = $this->find('count', array(
                'conditions'=>array('User.email_addr'=>$this->data['User']['email_addr']) )                        
                );
            if($result >0){
                $this->invalidate('username_unique');
                
            
                return false;
            }

            
        }
        return true;
    }
 
}

?>
